/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.webhomesites.locacao.model;

import br.com.webhomesites.padrao.utils.GenericDAO;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author Webhome
 */
public class EmitirContratoDAO extends GenericDAO<EmitirContratoModel> {
    
    public List<ItemLocacaoModel> findByIdLocacao(long idloc) {
        Query query = getEntityCriada().createNamedQuery("EmitirContratoModel.findByIdLocacao");
        query.setParameter("idloc", idloc);
        List<ItemLocacaoModel> retorno = query.getResultList();
        return retorno;
    }
    
    public long findMaxIdByIdLocacao(long idloc) {
        Query query = getEntityCriada().createNamedQuery("EmitirContratoModel.findMaxIdByIdLocacao");
        query.setParameter("idloc", idloc);
        
        if(query.getSingleResult()==null) {
            System.out.println("Item com retorno 0");
            return 0;
        } else {
        long retorno = (Long) query.getSingleResult();
            return retorno;
        }
    }
}
